﻿@page
@model Emprise.Web.Pages.User.LoginModel
@{
    ViewData["Title"] = "登录";
}
@{
    Layout = "_Layout";
}
<div class="big_bg" id="app">
    <div class="nav">
        <h2 class="nav-title">登录</h2>
    </div>

    <div class="main">
        <div>

            <div class="login-nonreg">
                <form>
                    <div class="form-text-login">
                        <label>邮箱：</label>
                        <input type="text" class="form-text" v-model="email" tabindex="1" autocomplete="new-password" />
                        <a href="javascript:;" class="form-text-clear" v-show="email" v-on:click="email=''"><i class="icon icon-clear"></i></a>
                    </div>

                    <div class="form-text-login">
                        <label>密码：</label>
                        <input type="password" class="form-text" v-model="password" v-on:keyup.13="login" tabindex="2" autocomplete="new-password" />
                        <a href="javascript:;" class="form-text-clear" v-show="password" v-on:click="password=''"><i class="icon icon-clear"></i></a>
                    </div>
                    <div class="fn-mt-login fn-mlr" style="text-align:right;">
                        <a style="font-size:12px;" href="@(Url.Page("/User/ForgotPassword"))">忘记密码?</a>
                    </div>
                </form>
            </div>
            <div class="fn-mt-login fn-mlr">
                <a class="btn btn-bar-tawny" href="javascript:;" v-on:click="login" tabindex="3"> 确 定 </a>
            </div>
            <div class="fn-mt-login fn-mlr" style="text-align:right;">
                <a style="font-size:12px;" href="@(Url.Page("/User/Reg"))">还没有账号，立即注册</a>
            </div>
            <div class="fn-mt fn-mlr"><span class="tip01 tip01-warn tips">{{tips}}</span></div>
        </div>

        <div class="loading" v-show="loading">
            <img src="/images/loading.gif">
        </div>
    </div>

</div>

@await Html.PartialAsync("_Footer",Model.SiteConfig)

@section Scripts {
    <script type="text/javascript">
        var vm = new Vue({
            el: '#app',
            data: {
                email: "@(Model.Email)",
                password: "",
                tips: "",
                loading: 0
            },
            methods: {
                login: function () {
                    var that = this;
                    that.tips = "";

                    if (!that.email || !that.password) {
                        that.tips = "请输入邮箱和密码";
                        return false;
                    }

                    that.loading = 1;

                    axios.post("", {
                        email: that.email,
                        password: that.password
                    }, {
                        headers: {
                            RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value
                        }
                    })
                    .then(function (response) {
                        var result = response.data;
                        if (result.status) {
                            location.href = "@(Url.Page("/User/Index"))";
                        } else {
                            var error = result.errorMessage || "登录失败";
                            if (result.data) {
                                error += "<br>" + result.data;
                            }
                            that.tips = error;
                        }
                        that.loading = 0;
                    })
                    .catch(function (error) {
                        console.log(error);
                        that.loading = 0;
                    });
                }
            }
        });
    </script>
}
